import { LoggerService } from '@nestjs/common'
import { createLogger, format, Logger,transports } from 'winston'
import  *  as  winston  from  'winston';
import  'winston-daily-rotate-file';
import chalk from 'chalk'
 var transport = new winston.transports.DailyRotateFile({
   level: 'info',
     dirname: 'log',
    filename: 'application-%DATE%.log',
    datePattern: 'YYYY-MM-DD-HH',
    zippedArchive: true,
    maxSize: '20m',
    maxFiles: '14d'
  });
transport.on('error', error => {
    console.log(error)
    // log or handle errors here
  });

transport.on('rotate', (oldFilename, newFilename) => {
  console.log('newFilename:', oldFilename)
  console.log('newFilename:',newFilename)
    // do something fun
  });
export class CustomLogger implements LoggerService {
  private logger: Logger

  constructor() {
    this.logger = createLogger({
      level: 'debug',
      format: format.combine(format.colorize(), format.simple()),
      transports:transport
    })
  }

  log(message: string, context: string) {
    this.logger.log('info', `[${context}] ${message}`)
  }

  error(message: string, context: string) {
    this.logger.log('error', `[${context}] ${message}`)
  }

  warn(message: string, context: string) {
    this.logger.log('warn', `[${context}] ${message}`)
  }
}